package com.zgscwjm.taobaphelper.ui;

import android.content.Context;
import android.os.Message;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.zgscwjm.taobaphelper.BaseConfig;
import com.zgscwjm.taobaphelper.UpdateActivity;
import com.zgscwjm.taobaphelper.data.AppVersionPlay;
import com.zgscwjm.taobaphelper.exutils.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by fukunaka on 2017/3/9. 对应原ac类
 */

public  class thread_getversion implements Runnable{
    final UpdateActivity updateActivity;

    public thread_getversion(UpdateActivity updateActivity){
        this.updateActivity=updateActivity;
    }
    @Override
    public void run() {
         int i=0;
        Map hashmap=new HashMap();
        hashmap.put("appType",Integer.valueOf(UpdateActivity.code));
        Context applicationContext=this.updateActivity.getApplicationContext();
        Message obtainMessage=updateActivity.handler.obtainMessage();
        obtainMessage.what=504;
        String a= BaseConfig.a(BaseConfig.e,hashmap,applicationContext);
        if (StringUtils.isEmpty(a))
        {
            obtainMessage.obj=Integer.valueOf(0);
            this.updateActivity.handler.sendMessage(obtainMessage);
            return;
        }
        Gson gson=new Gson();
        JsonElement parse= new JsonParser().parse(a);
        if (!(parse==null || parse.isJsonNull()))
        {
            AppVersionPlay appVersionPlay=gson.fromJson(parse,AppVersionPlay.class);
            int versionCode=appVersionPlay.getVersionCode();
            UpdateActivity.downloadurl=appVersionPlay.getDownloadUrl();
            UpdateActivity.versionname=appVersionPlay.getVersionName();
            i=versionCode;
        }

        obtainMessage.obj=Integer.valueOf(i);
        updateActivity.handler.sendMessage(obtainMessage);

    }
}
